import Vue from 'vue'
import Router from 'vue-router'
import department from './model/department'
import approval from './model/approval'
import attendance from './model/attendance'
import employee from './model/employee'
import permission from './model/permission'
import role from './model/role'
import salary from './model/salary'
import social from './model/social'
Vue.use(Router)

/* Layout */
import Layout from '@/layout'
//静态路由
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true//控制路由是否在左侧nav区域显示
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }],
  },
  // 404 page must be placed at the end !!!
]
//动态路由
export const dynamicrouter = [department,
  approval,
  attendance,
  employee,
  permission,
  role,
  salary,
  social,]
const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes//默认导入静态路由
})

const router = createRouter()
//重置路由
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // 重置路由
}

export default router
